package org.example.service.impl;

import org.example.controller.CommonResponse;
import org.example.dao.AuthorRepository;
import org.example.entity.domain.Author;
import org.example.entity.dto.AuthorDTO;
import org.example.service.AuthorService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author Aaron
 * @since 2021/10/30 11:34
 * <p>描述：</p>
 */
@Service
public class AuthorServiceImpl implements AuthorService {

    private final AuthorRepository authorRepository;

    public AuthorServiceImpl(AuthorRepository authorRepository) {
        this.authorRepository = authorRepository;
    }

    @Override
    public CommonResponse<AuthorDTO> getAuthorById(Long id) {
        Author author = this.authorRepository.getOne(id);
        AuthorDTO authorDTO = new AuthorDTO();
        BeanUtils.copyProperties(author, authorDTO);
        return CommonResponse.success(authorDTO, "查询用户成功");
    }

}
